package com.csii.pos.uofplan;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.util.ConvertUtils;
import com.csii.pos.caacctewsu.CaAcctEwSu;
import com.csii.pos.dto.accountlimits.AccountLimitsRes;
import com.csii.pos.dto.accountlimits.AccountRes;
import com.csii.pos.dto.uofplan.UofPlanReq;
import com.csii.pos.dto.uofplan.UofPlanRes;
import com.csii.pos.scaleplan.IfbScalePlan;
import com.csii.pos.service.uofplan.UofPlanInspectService;
import com.csii.pos.uofplan.service.UofPlanDescService;
import com.csii.pos.uofplan.service.UofPlanService;
import com.csii.result.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author:
 * @create:
 */
@RestController
@Slf4j
public class UofPlanInspectController implements UofPlanInspectService {
    @Autowired
    private UofPlanService uofPlanService;
    @Resource
    private UofPlanDescService uofPlanDescService;
    /** 
     * @description: 资金计划核查查询
     * @param: uofPlanReq 
     * @return:  查询到的list集合
     * @author liuzhonghua
     * @date:  2021-7-22
     */ 
    @Override
    public UofPlanRes checkPositionPlan(UofPlanReq uofPlanReq) {
        UofPlanPo uofPlanPo = new UofPlanPo();
        //数据转化UofPlanReq到uofPlanPo
        if (uofPlanReq!=null) {
            uofPlanPo.setUofStartDate(uofPlanReq.getUofItemDt());
            uofPlanPo.setUofPlanItlNo(uofPlanReq.getUofItemDept());
            if (!StringUtils.isEmpty(uofPlanReq.getUofItemNo())) {
                uofPlanPo.setUofItemSn(Long.parseLong(uofPlanReq.getUofItemNo()));
            }
        }
        uofPlanPo.setUofPlanType("week");
        List<UofPlanPo> uofPlanRess = uofPlanService.checkPositionPlan(uofPlanPo);
        //将list中实体类数据转化为对方需要的参数名
        List<UofPlanInspectVo> list = changeVo(uofPlanRess,uofPlanDescService);
        UofPlanRes uofPlanRes = new UofPlanRes();
        if (uofPlanReq!=null) {
            uofPlanRes = ConvertUtils.convert(UofPlanRes.class, uofPlanReq);
        }
        uofPlanRes.setCode("200");
        uofPlanRes.setData(list);
        return uofPlanRes;
    }

    private List<UofPlanInspectVo> changeVo(List<UofPlanPo> list,UofPlanDescService uofPlanDescService){
        //返回的list
        List<UofPlanInspectVo> uofPlanInspectVos = new ArrayList<>();
        //循环存入数据
        for (UofPlanPo u:list) {
            UofPlanInspectVo uofPlanInspectVo = new UofPlanInspectVo();
            uofPlanInspectVo.setUofItemAmt(u.getUofItemAmt());
            uofPlanInspectVo.setUofItemNo(u.getUofItemSn());
            uofPlanInspectVo.setUnit("亿元");
            uofPlanInspectVo.setUofItemDept(u.getUofPlanItlNo());
            uofPlanInspectVo.setUofItemDt(u.getUofStartDate());
            uofPlanInspectVo.setUofItemDesc(u.getUofItemDesc());
            uofPlanInspectVo.setUofItemType(u.getUofPlanType());
            UofPlanDesc byId = uofPlanDescService.getById(u.getUofItemSn());
            uofPlanInspectVo.setRows(byId);
            uofPlanInspectVos.add(uofPlanInspectVo);
        }

        return uofPlanInspectVos;
    }
}
